import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
import time
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from common.logger import logger
from common.jiguang import get_jiguang_token

def take_account(token):
    try:
        url = "http://218.6.172.239:3768/api/park/su/account"
        params = {"token": token}
        rsp = requests.get(url, params=params, timeout = 100)
        rspJson = rsp.json()
        return rspJson
    except Exception as e:
        print("获取速停车账号失败:" + repr(e))
        
    return None
       
if __name__ == '__main__':
    
    try:
        print("开始补充速停车账号...")
        thread_count = 20
        thread_pool = ThreadPoolExecutor(max_workers=thread_count)

        jiguang_token = get_jiguang_token()
        
        futures = []
        for i in range(thread_count):
            futures.append(thread_pool.submit(take_account, jiguang_token))
            time.sleep(1)
            
        for future in as_completed(futures):
            token = future.result()
            logger.success(token)
        thread_pool.shutdown(wait=True)
        
    except Exception as e:
        logger.exception(e)